package com.example.lotterysystem.service.iml;

import com.example.lotterysystem.common.errorcode.ServiceErrorCodeConstants;
import com.example.lotterysystem.common.exception.ServiceException;
import com.example.lotterysystem.common.utils.CaptchaUtil;
import com.example.lotterysystem.common.utils.RedisUtil;
import com.example.lotterysystem.common.utils.RegexUtil;
import com.example.lotterysystem.service.VerificationCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class VerificationCodeServiceImpl implements VerificationCodeService {


    // 对于redis里面的key需要标准化：为了区分业务，应该给key定义前缀：
    // VerificationCode_13111111111:1233、User_13111111111:userInfo

    private static final String VERIFICATION_CODE_PREFIX = "VERIFICATION_CODE_";
    private static final Long VERIFICATION_CODE_TIMEOUT = 60L;
    private static final String VERIFICATION_CODE_TEMPLATE_CODE = "SMS_465324787";

    @Autowired
   private RedisUtil redisUtil;



    @Override
    public void sendVerificationCode(String phoneNumber) {

        if(!RegexUtil.checkMobile(phoneNumber)){
            throw new ServiceException(ServiceErrorCodeConstants.PHONE_NUMBER_ERROR);
        }
        String code=CaptchaUtil.getCaptcha(4);


        //****************************

//        短信验证码模块，后面自己补充



        //****************************


    }

    @Override
    public String getVerificationCode(String phoneNumber) {
        if(!RegexUtil.checkMobile(phoneNumber)){
            throw new ServiceException(ServiceErrorCodeConstants.PHONE_NUMBER_ERROR);
        }

        return redisUtil.get(phoneNumber);
    }
}
